/**
 *  Written by Tyler Montbriand in 2004
 *  1005 freeware, do whatever the hell you want with it
 */

#include <stdlib.h>
#include "sdlext.h"

AudioSpec::AudioSpec(int _freq, int _format, int _channels, int _samples,
  void (*_callback)(void *, Uint8 *, int), void *_userdata)
{
  freq=_freq;
  format=_format;
  channels=_channels;
  samples=_samples;
  if(_callback!=NULL)
    callback=_callback;
  else
    callback=default_callback;

  userdata=_userdata;
}

void AudioSpec::default_callback(void *userdata, Uint8 *stream, int len)
{
  fprintf(stderr,"userdata(%p) stream(%p) len(%d)\n",userdata,stream,len);
}


void SDL_emucfg::PrintSettings()
{
  fprintf(stderr,"frequency(%u)\n",frequency);
  fprintf(stderr,"bitsPerSample(%d)\n",bitsPerSample);
  fprintf(stderr,"sampleFormat(%d)\n",sampleFormat);
  fprintf(stderr,"channels(%d)\n",channels);
  fprintf(stderr,"sidChips(%d)\n",sidChips);
  fprintf(stderr,"volumeControl(%d)\n",volumeControl);
  fprintf(stderr,"mos8580(%d)\n",mos8580);
  fprintf(stderr,"measuredVolume(%d)\n",measuredVolume);
  fprintf(stderr,"emulateFilter(%d)\n",emulateFilter);
  fprintf(stderr,"filterFs(%f)\n",filterFs);
  fprintf(stderr,"filterFm(%f)\n",filterFm);
  fprintf(stderr,"filterFt(%f)\n",filterFt);
  fprintf(stderr,"memoryMode(%d)\n",memoryMode);
  fprintf(stderr,"clockSpeed(%d)\n",clockSpeed);
  fprintf(stderr,"forceSongSpeed(%d)\n",forceSongSpeed);
  fprintf(stderr,"digiPlayerScans(%d)\n",digiPlayerScans);
  fprintf(stderr,"autoPanning(%d)\n",autoPanning);
}

SDL_emucfg::SDL_emucfg(SDL_AudioSpec spec)
{
  frequency=spec.freq;
  channels=spec.channels;
  sidChips=1;

  clockSpeed=SIDTUNE_CLOCK_NTSC;
  memoryMode=MPU_BANK_SWITCHING;

  emulateFilter=true;
  filterFs=SIDEMU_DEFAULTFILTERFS;
  filterFm=SIDEMU_DEFAULTFILTERFM;
  filterFt=SIDEMU_DEFAULTFILTERFT;

  mos8580=false;
  measuredVolume=true;
  autoPanning=SIDEMU_NONE;
  forceSongSpeed=true;
  digiPlayerScans=500;
  volumeControl=SIDEMU_NONE;

  switch(spec.format)
  {
  case AUDIO_S8:
    sampleFormat=SIDEMU_SIGNED_PCM;
    bitsPerSample=SIDEMU_8BIT;
    break;
  case AUDIO_U8:
    sampleFormat=SIDEMU_UNSIGNED_PCM;
    bitsPerSample=SIDEMU_8BIT;
    break;
  case AUDIO_S16:
    sampleFormat=SIDEMU_SIGNED_PCM;
    bitsPerSample=SIDEMU_16BIT;
    break;
  case AUDIO_U16:
    sampleFormat=SIDEMU_UNSIGNED_PCM;
    bitsPerSample=SIDEMU_16BIT;
    break;
  }
}
